package com.woniuxy.his.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniuxy.his.controller.form.AddArrangeForm;
import com.woniuxy.his.entity.Arrange;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.his.vo.ArrangeVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 排班表 Mapper 接口
 * </p>
 *
 * @author Lucas
 * @since 2021-08-24
 */
public interface ArrangeMapper extends BaseMapper<Arrange> {

    @Select("<script>select harr.arrange_id,hdoc.doctor_name,hdep.dep_name,harr.arrange_time from his_arrange harr join his_doctor hdoc join his_department hdep on harr.doctor_id=hdoc.doctor_id and  hdoc.dep_id=hdep.dep_id <where> <if test='arrangeTime!=null'> arrange_time =#{arrangeTime}</if></where></script>")
    public IPage<ArrangeVo> findArrangeByTime(IPage<ArrangeVo> page, String arrangeTime);

    @Select("select harr.arrange_id,hdoc.doctor_name,hdep.dep_name,harr.arrange_time from his_arrange harr join his_doctor hdoc join his_department hdep on harr.doctor_id=hdoc.doctor_id and  hdoc.dep_id=hdep.dep_id")
    public IPage<ArrangeVo> findArrangeByTime2(IPage<ArrangeVo> page);

    @Delete("delete from his_arrange where arrange_id=#{arrangeId}")
    public Integer delArrange(Integer arrangeId);


    @Select("select * from his_arrange where doctor_id=#{doctorId}")
    Arrange findArrangeByDoctorId(Integer doctorId);

    @Update("update his_arrange set arrange_time=#{arrangeTime} where arrange_id=#{arrangeId}")
    Integer updateArrange(AddArrangeForm addArrangeForm);

    @Update("update his_arrange set arrange_num=#{arrangeNum} where doctor_id=#{doctorId}")
    Integer updateArrangeNumByDoctorId(Arrange arrange);
}
